package com.yidu.t299.dao.xp;
import com.yidu.t299.domain.xp.Class;
import  com.yidu.t299.domain.xp.LatencyenrolPanel;
import com.yidu.t299.domain.xp.Record;
import com.yidu.t299.domain.xp.School;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

/*
使用Mybatis逆向生成自动生成 后续自己更改
 */
@Mapper
public interface LatencyenrolPanelMapper {
    /**
     * 根据报名编号删除
     * @param clientId 报名编号
     * @return
     */
    @Delete({
        "delete from latencyenrol_panel",
        "where client_id = #{clientId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer clientId);

    /**
     * 增加报名信息
     * @param record 报名对象
     * @return 影响的行数(返回1则成功)
     */
    @Insert({
        "insert into latencyenrol_panel (client_id, client_name, ",
        "client_sex, client_estate, ",
        "client_date, client_qq, ",
        "client_phone, class_id, ",
        "school_id, record_id, ",
        "talk_date, client_number, ",
        "source_id, client_age, ",
        "client_address)",
        "values (#{clientId,jdbcType=INTEGER}, #{clientName,jdbcType=VARCHAR}, ",
        "#{clientSex,jdbcType=VARCHAR}, #{clientEstate,jdbcType=VARCHAR}, ",
        "#{clientDate,jdbcType=VARCHAR}, #{clientQq,jdbcType=VARCHAR}, ",
        "#{clientPhone,jdbcType=VARCHAR}, #{classId,jdbcType=INTEGER}, ",
        "#{schoolId,jdbcType=INTEGER}, #{recordId,jdbcType=INTEGER}, ",
        "#{talkDate,jdbcType=VARCHAR}, #{clientNumber,jdbcType=INTEGER}, ",
        "#{sourceId,jdbcType=INTEGER}, #{clientAge,jdbcType=INTEGER}, ",
        "#{clientAddress,jdbcType=VARCHAR})"
    })
    int insert(LatencyenrolPanel record);

    /**
     * 根据报名编号查询指定信息
     * @param clientId 报名编号
     * @return
     */
    @Select({
        "select",
        "client_id, client_name, client_sex, client_estate, client_date, client_qq, client_phone, ",
        "class_id, school_id, record_id, talk_date, client_number, source_id, client_age, ",
        "client_address",
        "from latencyenrol_panel",
        "where client_id = #{clientId,jdbcType=INTEGER}"
    })
    @Results(id = "latencyenrolpanelMap",value = {
        @Result(column="client_id", property="clientId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="client_name", property="clientName", jdbcType=JdbcType.VARCHAR),
        @Result(column="client_sex", property="clientSex", jdbcType=JdbcType.VARCHAR),
        @Result(column="client_estate", property="clientEstate", jdbcType=JdbcType.VARCHAR),
        @Result(column="client_date", property="clientDate", jdbcType=JdbcType.VARCHAR),
        @Result(column="client_qq", property="clientQq", jdbcType=JdbcType.VARCHAR),
        @Result(column="client_phone", property="clientPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="class_id", property="classId", jdbcType=JdbcType.INTEGER),
        @Result(column="school_id", property="schoolId", jdbcType=JdbcType.INTEGER),
        @Result(column="record_id", property="recordId", jdbcType=JdbcType.INTEGER),
        @Result(column="talk_date", property="talkDate", jdbcType=JdbcType.VARCHAR),
        @Result(column="client_number", property="clientNumber", jdbcType=JdbcType.INTEGER),
        @Result(column="source_id", property="sourceId", jdbcType=JdbcType.INTEGER),
        @Result(column="client_age", property="clientAge", jdbcType=JdbcType.INTEGER),
        @Result(column="client_address", property="clientAddress", jdbcType=JdbcType.VARCHAR)
    })
    LatencyenrolPanel selectByPrimaryKey(Integer clientId);


    /**
     * 按条件分页查询报名数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 日志对象集合
     */
    @Select("select * from latencyenrol_panel cm " +
            "join class c " +
            "on cm.class_id=c.class_id " +
            "join school sm " +
            "on sm.school_id=cm.school_id " +
            "join record hy " +
            "on cm.record_id=hy.record_id where 1=1 ${condition} limit #{page},#{rows}")
    @Results({
            @Result(column = "client_id",property = "clientId",jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "client_name",property = "clientName",jdbcType = JdbcType.VARCHAR),
            @Result(column = "client_sex",property = "clientSex",jdbcType = JdbcType.VARCHAR),
            @Result(column = "client_estate",property = "clientEstate",jdbcType = JdbcType.VARCHAR),
            @Result(column = "client_date",property = "clientDate",jdbcType = JdbcType.VARCHAR),
            @Result(column = "client_qq",property = "clientQq",jdbcType = JdbcType.VARCHAR),
            @Result(column = "client_phone",property = "clientPhone",jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_id",property = "classId",jdbcType = JdbcType.INTEGER),
            @Result(column = "school_id",property = "schoolId",jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id",property = "recordId",jdbcType = JdbcType.INTEGER),
            @Result(column = "talk_date",property = "talkDate",jdbcType = JdbcType.VARCHAR),
            @Result(column = "client_number",property = "clientNumber",jdbcType = JdbcType.INTEGER),
            @Result(column = "source_id",property = "sourceId",jdbcType = JdbcType.INTEGER),
            @Result(column = "client_age",property = "clientAge",jdbcType = JdbcType.INTEGER),
            @Result(column = "client_address",property = "clientAddress",jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_name",property = "className",jdbcType = JdbcType.VARCHAR),
            @Result(column = "record_name",property = "recordName",jdbcType = JdbcType.VARCHAR),
            @Result(column = "school_name",property = "schoolName",jdbcType = JdbcType.VARCHAR)
    })
    List<LatencyenrolPanel> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询latencyenrol_panel表中数据行数 因为涉及了多表
     * 所以这里也需要多表联查不然无法设置条件
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from latencyenrol_panel cm " +
            "join class c " +
            "on cm.class_id=c.class_id " +
            "join school sm " +
            "on sm.school_id=cm.school_id " +
            "join record hy " +
            "on cm.record_id=hy.record_id  where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据报名信息修改其数据
     * @param record
     * @return
     */
    @Update({
        "update latencyenrol_panel",
        "set client_name = #{clientName,jdbcType=VARCHAR},",
          "client_sex = #{clientSex,jdbcType=VARCHAR},",
          "client_estate = #{clientEstate,jdbcType=VARCHAR},",
          "client_date = #{clientDate,jdbcType=VARCHAR},",
          "client_qq = #{clientQq,jdbcType=VARCHAR},",
          "client_phone = #{clientPhone,jdbcType=VARCHAR},",
          "class_id = #{classId,jdbcType=INTEGER},",
          "school_id = #{schoolId,jdbcType=INTEGER},",
          "record_id = #{recordId,jdbcType=INTEGER},",
          "talk_date = #{talkDate,jdbcType=VARCHAR},",
          "client_number = #{clientNumber,jdbcType=INTEGER},",
          "source_id = #{sourceId,jdbcType=INTEGER},",
          "client_age = #{clientAge,jdbcType=INTEGER},",
          "client_address = #{clientAddress,jdbcType=VARCHAR}",
        "where client_id = #{clientId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(LatencyenrolPanel record);

    //以下是获取下拉框数据的方法

    /**
     * 得到所有校区名称信息
     * @return 校区名称集合
     */
    @Select("select school_name from school")
    @Results({
            @Result(id = true,column = "school_name",property = "schoolName")
    })
    List<School> selectAllGetSchoolName();

    /**
     * 得到所有班级名称信息
     * @return 校区名称集合
     */
    @Select("select class_name from class")
    @Results({
            @Result(id = true,column = "class_name",property = "className")
    })
    List<Class> selectAllGetClassName();

    /**
     * 得到所有教师名称信息
     * @return 校区名称集合
     */
    @Select("select record_name from record")
    @Results({
            @Result(id = true,column = "record_name",property = "recordName")
    })
    List<Record> selectAllGetRecordName();


    /**
     *针对校区表(school)进行操作
     * 根据校区名称查找其编号
     * @param schoolName 校区名称
     * @return 影响的行数(>1:成功)
     */
    @Select("select school_id from school where school_name=#{schoolName}")
    int selectBySchoolName(@Param("schoolName") String schoolName);

    /**
     *针对班级表(class)进行操作
     * 根据班级名称查找其编号
     * @param className 班级名称
     * @return 影响的行数(>1:成功)
     */
    @Select("select class_id from class where class_name=#{className}")
    int selectByClassName(@Param("className") String className);

    /**
     *针对教师表(record)进行操作
     * 根据教师名称查找其编号
     * @param recordName 教师姓名
     * @return 影响的行数(>1:成功)
     */
    @Select("select record_id from record where record_name=#{recordName}")
    int selectByRecordName(@Param("recordName") String recordName);
}